<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="container">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>

    <div class="container2">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>

    <div class="container3">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>
    <script>
        // 需求二： 多个选项卡； 函数的封装 ；

        function tab(btns, divs) {
            btns.forEach((btn, key) => {
                btn.onclick = function () {
                    console.log("点击了按钮", key);
                    // 需要把 索引和 按钮索引一样的显示出来 其他的隐藏 ；
                    divs.forEach((div, k) => {
                        if (key == k) {
                            //div 显示出来
                            div.style.display = "block";
                        } else {
                            div.style.display = "none";
                        }
                    })
                }
            })
        }

        // 第一个选项卡
        let btns = document.querySelectorAll(".container button");
        let divs = document.querySelectorAll(".container div");
        tab(btns, divs);

        // 第二个选项卡
        let btns2 = document.querySelectorAll(".container2 button");
        let divs2 = document.querySelectorAll(".container2 div");
        tab(btns2, divs2);


        // 第三个选项卡
        let btns3 = document.querySelectorAll(".container3 button");
        let divs3 = document.querySelectorAll(".container3 div");
        tab(btns3, divs3);



    </script>
</body>

</html>